﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Farkhod.QuickDataViewer;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace QuickDataViewer.Tests.Unit
{
    [TestClass]
    public class DAOTests
    {
        [TestMethod]
        public void GetDBNamePositiveTest()
        {
            string expected = "master";
            string actual = DBManager.Instance.GetDBName();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void GetDBNameNegativeTest()
        {
            string expected = "wrongDBName";
            string actual = DBManager.Instance.GetDBName();
            Assert.AreNotEqual(expected, actual);
        }
        
        [TestMethod]
        public void SetDBNamePositiveTest()
        {
            bool expected = true;
            bool actual = DBManager.Instance.SetDBName("northwind");
            Assert.AreEqual(expected, actual);
        }
        
        [TestMethod]
        public async Task GetDBsPositiveTest()
        {
            string existingDBName = "master";
            List<string> actual = await DBManager.Instance.GetDBs();
            Assert.IsTrue(actual.Contains(existingDBName));
        }

        [TestMethod]
        public async Task GetDBsNegativeTest()
        {
            string existingDBName = "impossible db !@#$ name";
            List<string> actual = await DBManager.Instance.GetDBs();
            Assert.IsFalse(actual.Contains(existingDBName));
        }
        
        [TestMethod]
        public async Task GetTablesPositiveTest()
        {
            DBManager.Instance.SetDBName("master");
            string existingTableInMasterName = "spt_monitor";
            List<string> actual = await DBManager.Instance.GetTables();
            Assert.IsTrue(actual.Contains(existingTableInMasterName));
        }

        [TestMethod]
        public async Task GetTablesNegativeTest()
        {
            string existingTableInMasterName = "impossible table @#$#$ name";
            List<string> actual = await DBManager.Instance.GetTables();
            Assert.IsFalse(actual.Contains(existingTableInMasterName));
        }

        [TestMethod]
        public async Task GetViewsPositiveTest()
        {
            DBManager.Instance.SetDBName("master");
            string existingViewInMasterName = "spt_values";
            List<string> actual = await DBManager.Instance.GetViews();
            Assert.IsTrue(actual.Contains(existingViewInMasterName));
        }

        [TestMethod]
        public async Task GetViewsNegativeTest()
        {
            string existingViewInMasterName = "impossible view @#$#$ name";
            List<string> actual = await DBManager.Instance.GetViews();
            Assert.IsFalse(actual.Contains(existingViewInMasterName));
        }
    }
}
